/*
 * HomeFrame.java
 *
 * Created on 6 novembre 2008, 11:24
 */

package GUI;


import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.Icon;
import javax.swing.ImageIcon;


/**
 *
 * @author  coco
 */
public class GraphicalUserInterface extends javax.swing.JFrame {
    
    
    /** Creates new form HomeFrame */
    public GraphicalUserInterface() {
        this.setSize(JFrame.MAXIMIZED_HORIZ, JFrame.MAXIMIZED_VERT);
        this.setResizable(true);
        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setTitle("Rent-A-Supercar");
        this.setVisible(true);
        initComponents();
        disableRentalTab();
        footerUserLabel.setText(GUI.LoginWindow.benutzername);
        if(GUI.LoginWindow.CanSeeHistories==false)
        {tabbedPane.setEnabledAt(5, false);historyButton.setEnabled(false);}
        if(GUI.LoginWindow.CanSeeStatistics==false)
        {tabbedPane.setEnabledAt(4, false);statsButton.setEnabled(false);}
        if(GUI.LoginWindow.CanManageUsers==false)
        {tabbedPane.setEnabledAt(3, false);employeeButton.setEnabled(false);}

                //ll GUI.LoginWindow.privilegien.equals("allohnehistorie")  GUI.LoginWindow.privilegien.equals("allohnehistorie") ll GUI.LoginWindow.privilegien.equals("allohnehistorie") ll GUI.LoginWindow.privilegien.equals("allohnehistorie") ll GUI.LoginWindow.privilegien.equals("allohnehistorie") ll GUI.LoginWindow.privilegien.equals("allohnehistorie"))
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPane = new javax.swing.JTabbedPane();
        homeTab = new javax.swing.JPanel();
        customerButton = new javax.swing.JButton();
        carButton = new javax.swing.JButton();
        returnButton = new javax.swing.JButton();
        historyButton = new javax.swing.JButton();
        statsButton = new javax.swing.JButton();
        employeeButton = new javax.swing.JButton();
        currentData = new GUI.currentDataFrame();
        carTab = new javax.swing.JPanel();
        customerTab = new javax.swing.JPanel();
        employeeTab = new javax.swing.JPanel();
        statsTab = new javax.swing.JPanel();
        historyTab = new javax.swing.JPanel();
        returnTab = new javax.swing.JPanel();
        rentalTab = new javax.swing.JPanel();
        footer = new javax.swing.JPanel();
        footerUserLabel = new javax.swing.JLabel();
        footerDateTime = new javax.swing.JLabel();
        menu = new javax.swing.JMenuBar();
        file = new javax.swing.JMenu();
        logout = new javax.swing.JMenuItem();
        quit = new javax.swing.JMenuItem();
        info = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        addWindowStateListener(new java.awt.event.WindowStateListener() {
            public void windowStateChanged(java.awt.event.WindowEvent evt) {
                formWindowStateChanged(evt);
            }
        });

        tabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabbedPaneStateChanged(evt);
            }
        });

        Icon icone = new ImageIcon("auto.gif");
        customerButton.setIcon(icone);
        customerButton.setText("Fahrzeuge");
        customerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerButtonActionPerformed(evt);
            }
        });

        icone = new ImageIcon("user.gif");
        carButton.setIcon(icone);
        carButton.setText("Kunden");
        carButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carButtonActionPerformed(evt);
            }
        });

        icone = new ImageIcon("zuruck.gif");
        returnButton.setIcon(icone);
        returnButton.setText("jButton1");
        returnButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                returnButtonActionPerformed(evt);
            }
        });

        icone = new ImageIcon("historie.gif");
        historyButton.setIcon(icone);
        historyButton.setText("jButton1");
        historyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historyButtonActionPerformed(evt);
            }
        });

        icone = new ImageIcon("stats.gif");
        statsButton.setIcon(icone);
        statsButton.setText("jButton1");
        statsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statsButtonActionPerformed(evt);
            }
        });

        icone = new ImageIcon("mitarbeiter.gif");
        employeeButton.setIcon(icone);
        employeeButton.setText("jButton1");
        employeeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                employeeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout homeTabLayout = new javax.swing.GroupLayout(homeTab);
        homeTab.setLayout(homeTabLayout);
        homeTabLayout.setHorizontalGroup(
            homeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(homeTabLayout.createSequentialGroup()
                .addGap(207, 207, 207)
                .addGroup(homeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addGroup(homeTabLayout.createSequentialGroup()
                        .addComponent(employeeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(statsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(historyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(homeTabLayout.createSequentialGroup()
                        .addComponent(customerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(carButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(returnButton, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(337, Short.MAX_VALUE))
            .addComponent(currentData, javax.swing.GroupLayout.DEFAULT_SIZE, 1342, Short.MAX_VALUE)
        );
        homeTabLayout.setVerticalGroup(
            homeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(homeTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(homeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(customerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(carButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(returnButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(homeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(employeeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(statsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(historyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(currentData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        tabbedPane.addTab("Hauptseite", homeTab);

        javax.swing.GroupLayout carTabLayout = new javax.swing.GroupLayout(carTab);
        carTab.setLayout(carTabLayout);
        carTabLayout.setHorizontalGroup(
            carTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        carTabLayout.setVerticalGroup(
            carTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        tabbedPane.addTab("Fahrzeuge", carTab);
        tabbedPane.removeTabAt(1);
        try{
            GUI.carTab cartab = new GUI.carTab();
            tabbedPane.addTab("Fahrzeuge", cartab);
        }
        catch(java.text.ParseException e){
            System.out.println("Erro!");
        }

        javax.swing.GroupLayout customerTabLayout = new javax.swing.GroupLayout(customerTab);
        customerTab.setLayout(customerTabLayout);
        customerTabLayout.setHorizontalGroup(
            customerTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        customerTabLayout.setVerticalGroup(
            customerTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        tabbedPane.addTab("Kunden", customerTab);
        tabbedPane.removeTabAt(2);
        try{
            GUI.customerTab customertab = new GUI.customerTab();
            tabbedPane.addTab("Kunden", customertab);
        }
        catch(java.text.ParseException e){
            System.out.println("Erro!");
        }

        javax.swing.GroupLayout employeeTabLayout = new javax.swing.GroupLayout(employeeTab);
        employeeTab.setLayout(employeeTabLayout);
        employeeTabLayout.setHorizontalGroup(
            employeeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        employeeTabLayout.setVerticalGroup(
            employeeTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        tabbedPane.addTab("Mitarbeiter", employeeTab);
        tabbedPane.removeTabAt(3);
        try{
            GUI.employeeTab employe = new GUI.employeeTab();
            tabbedPane.addTab("Mitarbeiter", employe);
        }
        catch(java.text.ParseException e){
            System.out.println("Erro!");
        }

        javax.swing.GroupLayout statsTabLayout = new javax.swing.GroupLayout(statsTab);
        statsTab.setLayout(statsTabLayout);
        statsTabLayout.setHorizontalGroup(
            statsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        statsTabLayout.setVerticalGroup(
            statsTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        GUI.statsTab statsTab = new GUI.statsTab();

        tabbedPane.addTab("Statistik", statsTab);

        javax.swing.GroupLayout historyTabLayout = new javax.swing.GroupLayout(historyTab);
        historyTab.setLayout(historyTabLayout);
        historyTabLayout.setHorizontalGroup(
            historyTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        historyTabLayout.setVerticalGroup(
            historyTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        tabbedPane.addTab("Historie", historyTab);
        tabbedPane.removeTabAt(5);
        GUI.historyTab history = new GUI.historyTab();
        tabbedPane.addTab("Historie", history);

        javax.swing.GroupLayout returnTabLayout = new javax.swing.GroupLayout(returnTab);
        returnTab.setLayout(returnTabLayout);
        returnTabLayout.setHorizontalGroup(
            returnTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        returnTabLayout.setVerticalGroup(
            returnTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        tabbedPane.addTab("Fahrzeugzurückgabe", returnTab);
        tabbedPane.removeTabAt(6);
        GUI.returnTab retur = new GUI.returnTab();
        tabbedPane.addTab("Fahrzeugzurückgabe", retur);

        javax.swing.GroupLayout rentalTabLayout = new javax.swing.GroupLayout(rentalTab);
        rentalTab.setLayout(rentalTabLayout);
        rentalTabLayout.setHorizontalGroup(
            rentalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1342, Short.MAX_VALUE)
        );
        rentalTabLayout.setVerticalGroup(
            rentalTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 631, Short.MAX_VALUE)
        );

        GUI.rentalTab rentalTab = new GUI.rentalTab();

        tabbedPane.addTab("Verleih", rentalTab);

        footer.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        footerUserLabel.setText("Username");

        footerDateTime.setText("Datum und Uhrzeit");

        javax.swing.GroupLayout footerLayout = new javax.swing.GroupLayout(footer);
        footer.setLayout(footerLayout);
        footerLayout.setHorizontalGroup(
            footerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, footerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(footerUserLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1186, Short.MAX_VALUE)
                .addComponent(footerDateTime)
                .addContainerGap())
        );
        footerLayout.setVerticalGroup(
            footerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(footerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(footerDateTime)
                .addComponent(footerUserLabel))
        );

        file.setText("Datei");

        logout.setText("Logout");
        logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutActionPerformed(evt);
            }
        });
        file.add(logout);

        quit.setText("Quit");
        quit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitActionPerformed(evt);
            }
        });
        file.add(quit);

        menu.add(file);

        info.setText("Info");
        menu.add(info);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(footer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1347, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 656, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(footer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void enabled(){
        this.setEnabled(false);
    }
private void logoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutActionPerformed
        int retour = JOptionPane.showConfirmDialog(this,"Sind Sie sicher ? ", "Beenden",JOptionPane.OK_CANCEL_OPTION);
        if(retour==JOptionPane.OK_OPTION){
            kernel.Login.Logout(GUI.LoginWindow.sessionID);
    this.setVisible(false);
LoginWindow Frame=new LoginWindow();
        }


}//GEN-LAST:event_logoutActionPerformed

private void formWindowStateChanged(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowStateChanged
}//GEN-LAST:event_formWindowStateChanged

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        int retour = JOptionPane.showConfirmDialog(this,"Sind Sie sicher ? ", "Beenden",JOptionPane.OK_CANCEL_OPTION);
        if(retour==JOptionPane.OK_OPTION){
        kernel.Login.Logout(GUI.LoginWindow.sessionID);
        System.exit(0);
        }
}//GEN-LAST:event_formWindowClosing

private void customerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerButtonActionPerformed
    tabbedPane.setSelectedIndex(1);
    GUI.carTab.currentData.updateCustomer();
    GUI.carTab.currentData.updateCar();
}//GEN-LAST:event_customerButtonActionPerformed

private void carButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carButtonActionPerformed
    tabbedPane.setSelectedIndex(2);
    GUI.customerTab.currentData.updateCustomer();
    GUI.customerTab.currentData.updateCar();
}//GEN-LAST:event_carButtonActionPerformed

private void returnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_returnButtonActionPerformed
tabbedPane.setSelectedIndex(6);
}//GEN-LAST:event_returnButtonActionPerformed

private void employeeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_employeeButtonActionPerformed
tabbedPane.setSelectedIndex(3);
}//GEN-LAST:event_employeeButtonActionPerformed

private void statsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statsButtonActionPerformed
tabbedPane.setSelectedIndex(4);
}//GEN-LAST:event_statsButtonActionPerformed

private void historyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historyButtonActionPerformed
tabbedPane.setSelectedIndex(5);
}//GEN-LAST:event_historyButtonActionPerformed

private void tabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabbedPaneStateChanged
// TODO add your handling code here:
    int index = tabbedPane.getSelectedIndex();
    switch(index){
        case 0 : currentData.updateCustomer();
                 currentData.updateCar();
                 break;
        case 1 : GUI.carTab.currentData.updateCustomer();
                 GUI.carTab.currentData.updateCar();
                 break;
        case 2 : GUI.customerTab.currentData.updateCustomer();
                 GUI.customerTab.currentData.updateCar();
                 break;
        case 7 : GUI.rentalTab.updateCustomer();
                 GUI.rentalTab.updateCar();
                 break;
    }
}//GEN-LAST:event_tabbedPaneStateChanged

private void quitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitActionPerformed
        int retour = JOptionPane.showConfirmDialog(this,"Sind Sie sicher ? ", "Beenden",JOptionPane.OK_CANCEL_OPTION);
        if(retour==JOptionPane.OK_OPTION){
        kernel.Login.Logout(GUI.LoginWindow.sessionID);
        System.exit(0);
        }
}//GEN-LAST:event_quitActionPerformed


public static void enableRentalTab(){
    tabbedPane.setEnabledAt(7, true);
    
}

public static void disableRentalTab(){
    tabbedPane.setEnabledAt(7, false);
}

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                        new GraphicalUserInterface().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton carButton;
    private javax.swing.JPanel carTab;
    private GUI.currentDataFrame currentData;
    private javax.swing.JButton customerButton;
    private javax.swing.JPanel customerTab;
    private javax.swing.JButton employeeButton;
    private javax.swing.JPanel employeeTab;
    private javax.swing.JMenu file;
    private javax.swing.JPanel footer;
    public javax.swing.JLabel footerDateTime;
    private javax.swing.JLabel footerUserLabel;
    private javax.swing.JButton historyButton;
    private javax.swing.JPanel historyTab;
    private javax.swing.JPanel homeTab;
    private javax.swing.JMenu info;
    private javax.swing.JMenuItem logout;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenuItem quit;
    private javax.swing.JPanel rentalTab;
    private javax.swing.JButton returnButton;
    private javax.swing.JPanel returnTab;
    private javax.swing.JButton statsButton;
    private javax.swing.JPanel statsTab;
    public static javax.swing.JTabbedPane tabbedPane;
    // End of variables declaration//GEN-END:variables
    static public kernel.Customer selectedCustomer = new kernel.Customer();
    static public ArrayList<kernel.Car> selectedCar = new ArrayList<kernel.Car>() {};    
}
